package asteroids.model.programs.unaryexpression;

import asteroids.model.*;
import asteroids.model.programs.*;
import be.kuleuven.cs.som.annotate.Basic;
import exception.IllegalOperandException;

public class Coordinate extends UnaryExpression<Double> {

	public Coordinate(Expression<?> operand,boolean position, boolean x) throws IllegalOperandException {
		super(operand);
		this.position = position;
		this.x=x;
	}

	@Override
	public Double getValue(Program program) {
		if(getPosition())
			return getCoordinate(((SpaceObject)getOperand().getValue(program)).getPosition());
		return getCoordinate(((SpaceObject)getOperand().getValue(program)).getVelocity());
	}
	

	
	private Double getCoordinate(Vector vector){
		if(getX())
			return vector.getX();
		else return vector.getY();
	}

	
	@Basic
	private boolean getPosition(){
		return position;
	}
	
	private boolean position;
	
	@Basic
	private boolean getX(){
		return x;
	}
	
	public boolean x;

}
